﻿#include "password_line_edit.h"
#include <QKeyEvent>

PasswordLineEdit::PasswordLineEdit(QWidget *parent)
    : QLineEdit(parent)
{
    //设置无右键菜单
    setContextMenuPolicy(Qt::NoContextMenu);
    //设置无输入时密码提示
    setPlaceholderText(QStringLiteral("请输入密码"));
    //设置密码隐藏
    setEchoMode(QLineEdit::Password);
    //设置最大长度16位
    setMaxLength(16);
}

PasswordLineEdit::~PasswordLineEdit()
{
}

//屏蔽输入框全选、复制、粘贴功能
void PasswordLineEdit::keyPressEvent(QKeyEvent *event)
{
    if(event->matches(QKeySequence::SelectAll)
            || event->matches(QKeySequence::Copy)
            || event->matches(QKeySequence::Paste))
    {
        return;
    }

    QLineEdit::keyPressEvent(event);
}

//鼠标位于密码框中时不可移动
void PasswordLineEdit::mouseMoveEvent(QMouseEvent *event)
{
    Q_UNUSED(event);
}

//鼠标位于密码框中时不可移动
void PasswordLineEdit::mouseDoubleClickEvent(QMouseEvent *event)
{
    Q_UNUSED(event);
}
